-- spleefblock.lua
------------------------------------------------------------------------------
-- Title: Spleef Block
-- Authors: Jack Zackowitz, Jeremy Wolff
-- Description: Spleef block behavior
------------------------------------------------------------------------------

blockID = kgp.objectgetid()
gTick = 1
countdown = false

-- urls to the textures we need
NORMAL_TEXTURE = "filestore9/5368611/6693079/Red_001.jpg"
BREAK1_TEXTURE = "filestore9/5368611/6693080/Red_002.jpg"
BREAK3_TEXTURE = "filestore9/5368611/6693081/Red_003.jpg"

kgp.objectsettexture(blockID, NORMAL_TEXTURE, true)

--sets a trigger for the block
-- too small
--kgp.objectsettrigger(blockID, 8.8, blockID)
kgp.objectsettrigger(blockID, 9, blockID)

-- FIXME:
--timer function that constantly listens if a block has been stepped on, (countdown == true)
--counts up from that point until the block should be deleted, then deletes it.
function kgp_timer(tick)
  if countdown == true then
    if tick - gTick > 1000 then
      kgp.objectsettexture(blockID, BREAK3_TEXTURE, true)
      if tick - gTick > 2000 then
        kgp.objectmove(blockID, 0, 0, 0, 0, 0, -1000, 0, 0, 0, 0, true)
      end
    end
  end
end

--trigger that sets a blocks "countdown" value to true if stepped on
function kgp_trigger(user, triggertype, playerposition, triggerposition, radius, param)
  if param == blockID then
    if triggertype == 1 then 
      kgp.objectsettexture(blockID, BREAK1_TEXTURE, true)
      gTick = kgp.scriptgettick()
      countdown = true
      -- remove the trigger, so we don't keep resetting it
      kgp.objectremovetrigger(blockID)
    end
  end
end
